

<?php
include "../../shared/config.php";
include "../../shared/lan.php";
include "../../shared/baidu_transapi.php";

$lang = $_SESSION["language"];
$em_n = $_POST['company_name'];
$em_d = $_POST['detail'];
$em_c=$_POST['contact'];
$un = $login_session;


//自动翻译
if($lang=="zh"){
	$sql = "INSERT INTO em (company_name, detail, contact, user_name,lan) VALUES ('$em_n', '$em_d', '$em_c', '$un','zh')";

	$insert = mysqli_query($conn,$sql);
	$from = "zh";
	$to = "en";
}
else{
	$sql = "INSERT INTO em_en (company_name, detail, contact, user_name,lan) VALUES ('$em_n', '$em_d', '$em_c', '$un','en')";
	$insert = mysqli_query($conn,$sql);
	$from = "en";
	$to = "zh";
}
$info_array = [$em_n,$em_d];
$new_array = [];

foreach($info_array as $word){
	$answer = translate($word,$from,$to);
	//echo $answer['trans_result'][0]['dst'];
	sleep(1);
	array_push($new_array,$answer['trans_result'][0]['dst']);
	
}



if($lang=="zh"){
	$sql = "INSERT INTO em_en (company_name, detail, contact,user_name,lan) VALUES ('$new_array[0]', '$new_array[1]', '$em_c','$un','en')";

	$insert = mysqli_query($conn,$sql);
}
else{
	$sql = "INSERT INTO em (company_name, detail, contact,user_name,lan) VALUES ('$new_array[0]', '$new_array[1]', '$em_c','$un','zh')";
	$insert = mysqli_query($conn,$sql);
}

if(!$insert)
    {  
        echo "无法新增术语信息: ".mysqli_error($conn);  
    }  
    else  
    {  
		header("location: ../../page/boss/index.php");
    } 

mysqli_close($conn);
?>